//
//  ViewController.m
//  网格
//
//  Created by 张钧 on 2017/6/20.
//  Copyright © 2017年 JinYun. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
{
    UICollectionView * _collection;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UICollectionViewFlowLayout * layout=[[UICollectionViewFlowLayout alloc]init];
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.itemSize =CGSizeMake(self.view.frame.size.width / 5 - 10, self.view.frame.size.height / 10+5);
    _collection=[[UICollectionView alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, 200) collectionViewLayout:layout];
//    _collection.centerXAnchor=self.view;
    _collection.pagingEnabled=YES;
    _collection.delegate=self;
    _collection.dataSource=self;
    _collection.contentSize=CGSizeMake(self.view.frame.size.width *2, 200);

    [self.view addSubview:_collection];
    
    [_collection registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 20;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{
    UICollectionViewCell * cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    NSArray* colorarr=@[[UIColor colorWithRed:253/255.0 green:101/255.0 blue:65/255.0 alpha:1.0],
                [UIColor colorWithRed:253/255.0 green:133/255.0 blue:68/255.0 alpha:1.0],
                [UIColor colorWithRed:253/255.0 green:160/255.0 blue:89/255.0 alpha:1.0],
                [UIColor colorWithRed:253/255.0 green:178/255.0 blue:82/255.0 alpha:1.0],
                [UIColor colorWithRed:185/255.0 green:195/255.0 blue:121/255.0 alpha:1.0],
                [UIColor colorWithRed:152/255.0 green:202/255.0 blue:151/255.0 alpha:1.0],
                        [UIColor colorWithRed:117/255.0 green:211/255.0 blue:186/255.0 alpha:1.0],[UIColor colorWithRed:253/255.0 green:101/255.0 blue:65/255.0 alpha:1.0],
                        [UIColor colorWithRed:253/255.0 green:133/255.0 blue:68/255.0 alpha:1.0],
                        [UIColor colorWithRed:253/255.0 green:160/255.0 blue:89/255.0 alpha:1.0],
                        [UIColor colorWithRed:253/255.0 green:178/255.0 blue:82/255.0 alpha:1.0],
                        [UIColor colorWithRed:185/255.0 green:195/255.0 blue:121/255.0 alpha:1.0],
                        [UIColor colorWithRed:152/255.0 green:202/255.0 blue:151/255.0 alpha:1.0],
                        [UIColor colorWithRed:117/255.0 green:211/255.0 blue:186/255.0 alpha:1.0],[UIColor colorWithRed:253/255.0 green:101/255.0 blue:65/255.0 alpha:1.0],
                        [UIColor colorWithRed:253/255.0 green:133/255.0 blue:68/255.0 alpha:1.0],
                        [UIColor colorWithRed:253/255.0 green:160/255.0 blue:89/255.0 alpha:1.0],
                        [UIColor colorWithRed:253/255.0 green:178/255.0 blue:82/255.0 alpha:1.0],
                        [UIColor colorWithRed:185/255.0 green:195/255.0 blue:121/255.0 alpha:1.0],
                        [UIColor colorWithRed:152/255.0 green:202/255.0 blue:151/255.0 alpha:1.0]];
    cell.backgroundColor=colorarr[indexPath.row];
 
    return cell;
}
//- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
//        return CGSizeMake(self.view.frame.size.width / 5 - 10, self.view.frame.size.height / 10+5);
//  
//}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
